$('.keyword').on('mouseover',function(){
    $(this).children('.add-keyword').css('display','inline-block');
})

$('.keyword').on('mouseout',function(){
    $(this).children('.add-keyword').css('display','none');
})

$('.add-keyword').on('click',function(){
    var id = $(this).attr('data-id');
    if(id == 1){
        $(this).attr('data-id',2);
        $(this).text('-');
        $(this).parent().parent().parent().after('<div class="layui-form-item"><label class="layui-form-label">关键词</label><div class="layui-input-block"><div style="width: 125px;display: inline-block;"><select name="match[]" style="width:50px" lay-verify="required"><option value="contain">半匹配</option><option value="equal">全匹配</option></select></div><div class="keyword"><div class="kw-ipt" style="margin: 0 4px;"><input type="text" name="keyword[]" value="" required lay-verify="required" placeholder="输入关键词" class="layui-input"></div><div class="add-keyword" data-id = 1>+</div></div></div></div>');
        $.ajaxSetup({
            cache:true,
        });
        $.getScript('/static/js/reply/main.js');
    }else{
        $(this).parent().parent().parent().remove();
    }
    form.render();
});


$('.reply-content-add').on('click',function(){
    var id = $(this).attr('data-id');
    if(id == 1){
        $(this).attr('data-id',2);
        $(this).animate({rotate: '45'}, 200);
        $(this).next('.reply-content-blank').children('.reply-content-type').animate({left:'0px'},200);
    }else{
        $(this).attr('data-id',1);
        $(this).animate({rotate: '0'}, 200);
        $(this).next('.reply-content-blank').children('.reply-content-type').animate({left:'-500px'},200);
    }
});

form.on('radio(type)', function(data){
    // console.log($(data.elem).parent().parent().parent().before('<div class="layui-input-block" style="height:38px;line-height:38px;border-bottom: 1px solid #ccc;padding-bottom: 8px;"><span class="reply-text">qwe</span></div>'));
//   console.log(data.elem); //得到radio原始DOM对象
//   console.log(data.value); //被点击的radio的value值
    if(data.value == 'text'){
        layer.open({
            type: 1,
            content: '<textarea style="width:100%;height:100%;resize: none;" autofocus name="content[]" placeholder="添加回复文字" class="layui-textarea"></textarea>', //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            resize:false,
            area: ['700px', '300px'],
            btn: ['确认', '取消']
                ,yes: function(index, layero){
                    var value = $(layero).children('.layui-layer-content').children('textarea').val()
                    $(data.elem).parent().parent().parent().before('<div class="layui-input-block" style="height:38px;line-height:38px;border-bottom: 1px solid #ccc;padding-bottom: 8px;"><input type="hidden" name="type[]" value="text" /><input readonly="readonly" type="hidden" name="content[]" value="'+value+'" /><span>'+value+'</span></div>')
                    layer.closeAll();
                    //按钮【按钮一】的回调
                }
                ,btn2: function(index, layero){
                    //按钮【按钮二】的回调
                    
                    //return false 开启该代码可禁止点击该按钮关闭
                }
          });
    }
});  

$('.reply-edit').on('click',function(){
    var content = $(this).prev('span').text();
    var ipt_content = $(this).prevAll('.reply-ipt-content')
    var type = $(this).prevAll('.reply-ipt-type');
    var that = this;
    if(type == 'text'){
        layer.open({
            type: 1,
            content: '<textarea style="width:100%;height:100%;resize: none;" autofocus name="content[]" placeholder="添加回复文字" class="layui-textarea">'+content+'</textarea>', //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            resize:false,
            area: ['700px', '300px'],
            btn: ['确认', '取消']
                ,yes: function(index, layero){
                    var value = $(layero).children('.layui-layer-content').children('textarea').val()
                    $(that).prev('span').text(value);
                    ipt_content.val(value);
                    layer.closeAll();
                    //按钮【按钮一】的回调
                }
                ,btn2: function(index, layero){
                    //按钮【按钮二】的回调
                    
                    //return false 开启该代码可禁止点击该按钮关闭
                }
          });
    }
});

$('.reply-del').on('click',function(){
    $(this).parent().remove();
});